package com.lanou.utp.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanou.utp.entity.Base;
import com.lanou.utp.mapper.BaseInfoMapper;
import com.lanou.utp.service.BaseInfoService;
import com.lanou.utp.entity.Paging;
import com.lanou.utp.entity.ResponseData;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author MaQingYun
 */
@Transactional
@Service
public class BaseInfoServiceImpl implements BaseInfoService {

    @Resource
    private BaseInfoMapper baseInfoMapper;

    @Override
    public void addBaseInfo(Base baseinfo) {
        this.baseInfoMapper.addBaseInfo(baseinfo);
    }

    @Override
    public ResponseData getBaseList(Integer page) {
        Page<Object> page1 = PageHelper.offsetPage((page-1)*Paging.size,Paging.size);
        List<Base> baseInfoList = this.baseInfoMapper.getBaseInfoList();
        Paging paging = new Paging(page,page1.getTotal());
        return new ResponseData(baseInfoList,paging);
    }

    @Override
    public void updateBaseInfo(Base baseinfo) {
        this.baseInfoMapper.updateBaseInfo(baseinfo);
    }

    @Override
    public void deleteByBaseId(Long id) {
        this.baseInfoMapper.deleteByBaseId(id);
    }

    @Override
    public void deleteBases(List list) {
        this.baseInfoMapper.deleteBases(list);
    }

}
